package com.zxmr.hospital.customer;

import java.io.File;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.zxmr.CommonInit;
import com.zxmr.component.SimpleServerStarter;
import com.zxmr.component.SystemConstant;
import com.zxmr.navigate.RequestDispatch;
import com.zxmr.navigate.XMLConfigurationLoader;
import com.zxmr.util.ResourceManager;
import com.zxmr.util.UserTraceManager;

public class Starter {

		public static final String queue = "zxmr.customer"; 
		static SimpleServerStarter starter = null;
		/**
		 * @param args
		 */
		public static void main(String[] args) {

			String basedir = System.getProperty("basedir");
			System.out.println("base dir is "+basedir);
			System.out.println(System.getProperties());
			SystemConstant.setBasedir(basedir+File.separator);
			
			CommonInit.initCommonSqlMapper(SystemConstant.getBasedir()+"common-part-db-config.xml");
			//startRequestDispatch();
			starter = new SimpleServerStarter();
			starter.start(queue, getExecutor());

			ResourceManager.getInstance();
			
			UserTraceManager.init();
		}
		private static ExecutorService getExecutor()
		{
			ExecutorService es = new ThreadPoolExecutor(1,2,5,TimeUnit.SECONDS,
					new ArrayBlockingQueue<Runnable>(100),
					new ThreadPoolExecutor.CallerRunsPolicy());
			return es;
		}
		private static void startRequestDispatch()
		{
			String url = "dispatch.xml";
			String propsPath = SystemConstant.getBasedir() + url;
			
			XMLConfigurationLoader loader = new XMLConfigurationLoader();
			loader.load(propsPath);
			
			RequestDispatch.init(loader);
		}

}
